{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "24202eb0",
   "metadata": {},
   "source": [
    "# 电商日志分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5485a3d5",
   "metadata": {},
   "source": [
    "## 1.数据导入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "869c07eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入必要的包以及要处理的数据\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os \n",
    "from collections import defaultdict\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "14944bcf",
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入数据\n",
    "df = pd.read_excel('D:\\pythonProject\\hdfsout.xls')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "ae2bf786",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户名</th>\n",
       "      <th>IP</th>\n",
       "      <th>访问深度</th>\n",
       "      <th>商品种类</th>\n",
       "      <th>成交时间</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>浏览器种类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>abai</td>\n",
       "      <td>4.113.156.144</td>\n",
       "      <td>9</td>\n",
       "      <td>美妆</td>\n",
       "      <td>15:45:40</td>\n",
       "      <td>浙江省福州市海港</td>\n",
       "      <td>Chrom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>acai</td>\n",
       "      <td>71.101.242.143</td>\n",
       "      <td>1</td>\n",
       "      <td>美妆</td>\n",
       "      <td>18:08:51</td>\n",
       "      <td>北京市邯郸县淄川</td>\n",
       "      <td>Chrom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>acao</td>\n",
       "      <td>96.184.171.120</td>\n",
       "      <td>6</td>\n",
       "      <td>服装</td>\n",
       "      <td>01:18:50</td>\n",
       "      <td>香港特别行政区贵阳县白云</td>\n",
       "      <td>IE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>achang</td>\n",
       "      <td>208.125.35.86</td>\n",
       "      <td>4</td>\n",
       "      <td>美妆</td>\n",
       "      <td>03:08:49</td>\n",
       "      <td>浙江省辉市平山</td>\n",
       "      <td>Chrom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>achen</td>\n",
       "      <td>196.187.59.116</td>\n",
       "      <td>4</td>\n",
       "      <td>食品</td>\n",
       "      <td>21:21:41</td>\n",
       "      <td>宁夏回族自治区敏市长寿</td>\n",
       "      <td>Chrom</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      用户名              IP  访问深度 商品种类      成交时间          收货地址  浏览器种类\n",
       "0    abai   4.113.156.144     9   美妆  15:45:40      浙江省福州市海港  Chrom\n",
       "1    acai  71.101.242.143     1   美妆  18:08:51      北京市邯郸县淄川  Chrom\n",
       "2    acao  96.184.171.120     6   服装  01:18:50  香港特别行政区贵阳县白云     IE\n",
       "3  achang   208.125.35.86     4   美妆  03:08:49       浙江省辉市平山  Chrom\n",
       "4   achen  196.187.59.116     4   食品  21:21:41   宁夏回族自治区敏市长寿  Chrom"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#预览数据\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "284ef4c5",
   "metadata": {},
   "source": [
    "## 2.数据查看"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b69b950c",
   "metadata": {},
   "source": [
    "### 2.1 数据描述"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "c5c50006",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户名</th>\n",
       "      <th>IP</th>\n",
       "      <th>访问深度</th>\n",
       "      <th>商品种类</th>\n",
       "      <th>成交时间</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>浏览器种类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>8233</td>\n",
       "      <td>8233</td>\n",
       "      <td>8233.000000</td>\n",
       "      <td>8233</td>\n",
       "      <td>8233</td>\n",
       "      <td>8233</td>\n",
       "      <td>8233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>8233</td>\n",
       "      <td>8233</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>7874</td>\n",
       "      <td>8193</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>abai</td>\n",
       "      <td>4.113.156.144</td>\n",
       "      <td>NaN</td>\n",
       "      <td>服装</td>\n",
       "      <td>11:39:52</td>\n",
       "      <td>湖南省南宁县沙湾</td>\n",
       "      <td>Chrom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2310</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.805539</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.880985</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         用户名             IP         访问深度  商品种类      成交时间      收货地址  浏览器种类\n",
       "count   8233           8233  8233.000000  8233      8233      8233   8233\n",
       "unique  8233           8233          NaN     8      7874      8193      5\n",
       "top     abai  4.113.156.144          NaN    服装  11:39:52  湖南省南宁县沙湾  Chrom\n",
       "freq       1              1          NaN  2310         3         2   2934\n",
       "mean     NaN            NaN     4.805539   NaN       NaN       NaN    NaN\n",
       "std      NaN            NaN     1.880985   NaN       NaN       NaN    NaN\n",
       "min      NaN            NaN     1.000000   NaN       NaN       NaN    NaN\n",
       "25%      NaN            NaN     3.000000   NaN       NaN       NaN    NaN\n",
       "50%      NaN            NaN     5.000000   NaN       NaN       NaN    NaN\n",
       "75%      NaN            NaN     6.000000   NaN       NaN       NaN    NaN\n",
       "max      NaN            NaN     9.000000   NaN       NaN       NaN    NaN"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe(include='all')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "259b9645",
   "metadata": {},
   "source": [
    "### 2.2 数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0e5d29d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "用户名      object\n",
       "IP       object\n",
       "访问深度      int64\n",
       "商品种类     object\n",
       "成交时间     object\n",
       "收货地址     object\n",
       "浏览器种类    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8671e5bd",
   "metadata": {},
   "source": [
    "> 我们发现有部分描述是无效的，查看数据类型后发现只有访问深度这一列有意义，为了更加突出，我们单独展示它。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "88eaa016",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>访问深度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>8233.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>4.805539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.880985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>6.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>9.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              访问深度\n",
       "count  8233.000000\n",
       "mean      4.805539\n",
       "std       1.880985\n",
       "min       1.000000\n",
       "25%       3.000000\n",
       "50%       5.000000\n",
       "75%       6.000000\n",
       "max       9.000000"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb301507",
   "metadata": {},
   "source": [
    "这样就比较清楚了，我们可以清晰的看到用户在购买时候的访问深度相关分析数据，我们在后面进行数据分析时候会用到相关数据。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58f8be5d",
   "metadata": {},
   "source": [
    "### 2.3 数据信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "422ad2ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 8233 entries, 0 to 8232\n",
      "Data columns (total 7 columns):\n",
      " #   Column  Non-Null Count  Dtype \n",
      "---  ------  --------------  ----- \n",
      " 0   用户名     8233 non-null   object\n",
      " 1   IP      8233 non-null   object\n",
      " 2   访问深度    8233 non-null   int64 \n",
      " 3   商品种类    8233 non-null   object\n",
      " 4   成交时间    8233 non-null   object\n",
      " 5   收货地址    8233 non-null   object\n",
      " 6   浏览器种类   8233 non-null   object\n",
      "dtypes: int64(1), object(6)\n",
      "memory usage: 450.4+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1eb845f2",
   "metadata": {},
   "source": [
    "## 3.数据处理及检查"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1e63089",
   "metadata": {},
   "source": [
    "注：由于我们的数据是经过kettle进行过去空、去重等清洗操作后导出来的，所以在这一步我们不再进行数据清洗，仅对上一步处理过的数据进行检查。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f599c2c5",
   "metadata": {},
   "source": [
    "### 3.1 空缺值检查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "cde517b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户名</th>\n",
       "      <th>IP</th>\n",
       "      <th>访问深度</th>\n",
       "      <th>商品种类</th>\n",
       "      <th>成交时间</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>浏览器种类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>字段类型</th>\n",
       "      <td>object</td>\n",
       "      <td>object</td>\n",
       "      <td>int64</td>\n",
       "      <td>object</td>\n",
       "      <td>object</td>\n",
       "      <td>object</td>\n",
       "      <td>object</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>空值数(条)</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>空值率(%)</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           用户名      IP   访问深度    商品种类    成交时间    收货地址   浏览器种类\n",
       "字段类型    object  object  int64  object  object  object  object\n",
       "空值数(条)       0       0      0       0       0       0       0\n",
       "空值率(%)     0.0     0.0    0.0     0.0     0.0     0.0     0.0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tab_info=pd.DataFrame(df.dtypes).T.rename(index={0:'字段类型'})\n",
    "tab_info=tab_info.append(pd.DataFrame(df.isnull().sum()).T.rename(index={0:'空值数(条)'}))\n",
    "tab_info=tab_info.append(pd.DataFrame(df.isnull().sum()/df.shape[0]*100).T.rename(index={0:'空值率(%)'}))\n",
    "display(tab_info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "caf9cc2c",
   "metadata": {},
   "source": [
    "### 3.2 异常值检查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "b0c593db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "重复的数据条目: 0\n"
     ]
    }
   ],
   "source": [
    "print('重复的数据条目: {}'.format(df.duplicated().sum()))\n",
    "df.drop_duplicates(inplace = True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f9c3cd1",
   "metadata": {},
   "source": [
    "通过以上步骤，可以发现，经过处理后的数据符合规范，我们可以进行下一步的分析。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86e3ead2",
   "metadata": {},
   "source": [
    "## 数据分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3fdad9f",
   "metadata": {},
   "source": [
    "### 4.1访问深度分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "8e82b9ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     333\n",
       "2     875\n",
       "3     901\n",
       "4    1367\n",
       "5    1291\n",
       "6    2060\n",
       "7     910\n",
       "8     339\n",
       "9     157\n",
       "Name: 访问深度, dtype: int64"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['访问深度'].value_counts().sort_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82d7f413",
   "metadata": {},
   "source": [
    "通过对访问深度进行统计并进行升序展示，可以得到用户在下单前的访问情况。可以看到我们的订单大多数都是在用户访问到第4-6个页面时完成的。考虑上顾客“货比三家”的心理，总体上我们对于用户的刻画比较精准，可以做到及时的抓住用户的需求，\n",
    "但同时可以看到，在7-9层，当用户访问越来越深时，我们的成交率也在逐渐下降。能进行深层次页面访问说明用户是存在需求的，但是最终没有成交的原因需要去探索，建议在用户退出时向他发送优惠券来留住客户，或者是发送调查问卷调查退出的原因以优化我们的系统。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37b0de8d",
   "metadata": {},
   "source": [
    "### 4.2.商品种类分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "6e642571",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "服装    2310\n",
       "美妆    1869\n",
       "食品    1484\n",
       "运动     931\n",
       "图书     681\n",
       "家电     479\n",
       "医疗     249\n",
       "工业     230\n",
       "Name: 商品种类, dtype: int64"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['商品种类'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e21c252",
   "metadata": {},
   "source": [
    "通过统计我们可以发现，用户最喜欢购买的商品种类是服装，而最不常购买的是工业用品。这可能和人们的购物喜好有关，\n",
    "也可能和需求有关。更重要的是工业用品一般都需要大量采购，是一笔不小的费用，人们会觉得网上的东西质量良莠不齐，应该加强\n",
    "用户和商家之间的沟通，消除信息差，以促进更多订单的完成。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "643dc5c8",
   "metadata": {},
   "source": [
    "### 4.3.成交时段分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "90924d7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['时段']=[x[:2] for x in df['成交时间']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "7dd639b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户名</th>\n",
       "      <th>IP</th>\n",
       "      <th>访问深度</th>\n",
       "      <th>商品种类</th>\n",
       "      <th>成交时间</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>浏览器种类</th>\n",
       "      <th>时段</th>\n",
       "      <th>省份</th>\n",
       "      <th>时段1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8228</th>\n",
       "      <td>zzhang</td>\n",
       "      <td>57.119.53.98</td>\n",
       "      <td>2</td>\n",
       "      <td>服装</td>\n",
       "      <td>16:52:12</td>\n",
       "      <td>北京市涛县吉区</td>\n",
       "      <td>FireFox</td>\n",
       "      <td>16</td>\n",
       "      <td>北京</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8229</th>\n",
       "      <td>zzhao</td>\n",
       "      <td>43.3.208.213</td>\n",
       "      <td>7</td>\n",
       "      <td>运动</td>\n",
       "      <td>00:02:00</td>\n",
       "      <td>湖北省帅县双滦</td>\n",
       "      <td>FireFox</td>\n",
       "      <td>00</td>\n",
       "      <td>湖北</td>\n",
       "      <td>00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8230</th>\n",
       "      <td>zzhou</td>\n",
       "      <td>220.241.136.233</td>\n",
       "      <td>5</td>\n",
       "      <td>美妆</td>\n",
       "      <td>21:46:48</td>\n",
       "      <td>青海省建华县沙湾</td>\n",
       "      <td>Chrom</td>\n",
       "      <td>21</td>\n",
       "      <td>青海</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8231</th>\n",
       "      <td>zzhu</td>\n",
       "      <td>113.230.209.33</td>\n",
       "      <td>5</td>\n",
       "      <td>工业</td>\n",
       "      <td>16:42:26</td>\n",
       "      <td>陕西省南昌市合川</td>\n",
       "      <td>IE</td>\n",
       "      <td>16</td>\n",
       "      <td>陕西</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8232</th>\n",
       "      <td>zzou</td>\n",
       "      <td>86.176.29.52</td>\n",
       "      <td>5</td>\n",
       "      <td>美妆</td>\n",
       "      <td>23:30:31</td>\n",
       "      <td>贵州省佛山县萧山</td>\n",
       "      <td>FireFox</td>\n",
       "      <td>23</td>\n",
       "      <td>贵州</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         用户名               IP  访问深度 商品种类      成交时间      收货地址    浏览器种类  时段  省份  \\\n",
       "8228  zzhang     57.119.53.98     2   服装  16:52:12   北京市涛县吉区  FireFox  16  北京   \n",
       "8229   zzhao     43.3.208.213     7   运动  00:02:00   湖北省帅县双滦  FireFox  00  湖北   \n",
       "8230   zzhou  220.241.136.233     5   美妆  21:46:48  青海省建华县沙湾    Chrom  21  青海   \n",
       "8231    zzhu   113.230.209.33     5   工业  16:42:26  陕西省南昌市合川       IE  16  陕西   \n",
       "8232    zzou     86.176.29.52     5   美妆  23:30:31  贵州省佛山县萧山  FireFox  23  贵州   \n",
       "\n",
       "     时段1  \n",
       "8228  16  \n",
       "8229  00  \n",
       "8230  21  \n",
       "8231  16  \n",
       "8232  23  "
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "3ea105c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "00    375\n",
       "01    351\n",
       "02    350\n",
       "03    344\n",
       "04    347\n",
       "05    318\n",
       "06    351\n",
       "07    357\n",
       "08    350\n",
       "09    339\n",
       "10    328\n",
       "11    332\n",
       "12    309\n",
       "13    325\n",
       "14    348\n",
       "15    333\n",
       "16    352\n",
       "17    345\n",
       "18    332\n",
       "19    339\n",
       "20    331\n",
       "21    380\n",
       "22    355\n",
       "23    342\n",
       "Name: 时段, dtype: int64"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict=df['时段'].value_counts().sort_index()\n",
    "dict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba832e31",
   "metadata": {},
   "source": [
    "经过分析可以看到我们的成交订单分散在各个时间段，因为是生成的数据，在这字段没有加权，从某种程度上来说这部分数据是无法模拟用户的行为的。正常来讲，长时间大规模的用户信息汇总起来，我们是可以得到一条曲线的。这条曲线可以为我们展现用户下单的峰值和低点。通过这些信息我们可以调整自己公司的相关营销策略，比如说用户平均订单量大的时间段，我们可以加大这个时间段的广告推送等等策略。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "bb77e98f",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (Temp/ipykernel_14964/442097183.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\陈元飞\\AppData\\Local\\Temp/ipykernel_14964/442097183.py\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    df['时段1']= pd.cut(x=df.'时段',bins=time_bins,labels=[\"深夜\",\"清晨\",\"上午\",\"下午\",\"傍晚\",\"夜晚\"])\u001b[0m\n\u001b[1;37m                              ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#time_bins = [0,5,8,12,17,19,23]\n",
    "#df['时段1']= pd.cut(x=df.'时段',bins=time_bins,labels=[\"深夜\",\"清晨\",\"上午\",\"下午\",\"傍晚\",\"夜晚\"])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3b67cfa",
   "metadata": {},
   "source": [
    "### 4.4用户地域信息分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "84c9e95a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['省份']=[x[:2] for x in df['收货地址']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "a5f098be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>用户名</th>\n",
       "      <th>IP</th>\n",
       "      <th>访问深度</th>\n",
       "      <th>商品种类</th>\n",
       "      <th>成交时间</th>\n",
       "      <th>收货地址</th>\n",
       "      <th>浏览器种类</th>\n",
       "      <th>时段</th>\n",
       "      <th>省份</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>abai</td>\n",
       "      <td>4.113.156.144</td>\n",
       "      <td>9</td>\n",
       "      <td>美妆</td>\n",
       "      <td>15:45:40</td>\n",
       "      <td>浙江省福州市海港</td>\n",
       "      <td>Chrom</td>\n",
       "      <td>15</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>acai</td>\n",
       "      <td>71.101.242.143</td>\n",
       "      <td>1</td>\n",
       "      <td>美妆</td>\n",
       "      <td>18:08:51</td>\n",
       "      <td>北京市邯郸县淄川</td>\n",
       "      <td>Chrom</td>\n",
       "      <td>18</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>acao</td>\n",
       "      <td>96.184.171.120</td>\n",
       "      <td>6</td>\n",
       "      <td>服装</td>\n",
       "      <td>01:18:50</td>\n",
       "      <td>香港特别行政区贵阳县白云</td>\n",
       "      <td>IE</td>\n",
       "      <td>01</td>\n",
       "      <td>香港</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>achang</td>\n",
       "      <td>208.125.35.86</td>\n",
       "      <td>4</td>\n",
       "      <td>美妆</td>\n",
       "      <td>03:08:49</td>\n",
       "      <td>浙江省辉市平山</td>\n",
       "      <td>Chrom</td>\n",
       "      <td>03</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>achen</td>\n",
       "      <td>196.187.59.116</td>\n",
       "      <td>4</td>\n",
       "      <td>食品</td>\n",
       "      <td>21:21:41</td>\n",
       "      <td>宁夏回族自治区敏市长寿</td>\n",
       "      <td>Chrom</td>\n",
       "      <td>21</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      用户名              IP  访问深度 商品种类      成交时间          收货地址  浏览器种类  时段  省份\n",
       "0    abai   4.113.156.144     9   美妆  15:45:40      浙江省福州市海港  Chrom  15  浙江\n",
       "1    acai  71.101.242.143     1   美妆  18:08:51      北京市邯郸县淄川  Chrom  18  北京\n",
       "2    acao  96.184.171.120     6   服装  01:18:50  香港特别行政区贵阳县白云     IE  01  香港\n",
       "3  achang   208.125.35.86     4   美妆  03:08:49       浙江省辉市平山  Chrom  03  浙江\n",
       "4   achen  196.187.59.116     4   食品  21:21:41   宁夏回族自治区敏市长寿  Chrom  21  宁夏"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "dbd63353",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "辽宁    277\n",
       "甘肃    271\n",
       "贵州    262\n",
       "浙江    260\n",
       "广西    258\n",
       "黑龙    256\n",
       "吉林    256\n",
       "河南    255\n",
       "福建    253\n",
       "四川    251\n",
       "青海    251\n",
       "河北    250\n",
       "山西    249\n",
       "江苏    249\n",
       "西藏    247\n",
       "陕西    246\n",
       "江西    242\n",
       "宁夏    241\n",
       "山东    241\n",
       "台湾    239\n",
       "重庆    237\n",
       "新疆    235\n",
       "海南    235\n",
       "澳门    232\n",
       "湖北    229\n",
       "内蒙    229\n",
       "上海    229\n",
       "云南    229\n",
       "广东    228\n",
       "安徽    225\n",
       "香港    223\n",
       "天津    220\n",
       "北京    218\n",
       "湖南    210\n",
       "Name: 省份, dtype: int64"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['省份'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f46a3ed5",
   "metadata": {},
   "source": [
    "通过对用户地域进行统计，我们可以发现我们的用户分布还是比较分散，相对平均的。这说明我们的平台受众广，推广范围广。\n",
    "可继续按当下公司的推广计划进行执行。同时对于一些热门城市，本应是市场更大，订单更多，但结果却是和其他地区水平相当。这说明，我们的平台只是推出去了，有人在用，但不是必不可少，没有与用户之间建立依赖，这是很大的问题，公司需要\n",
    "制定相关对策，解决这个问题，增加用户粘性。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd8330a6",
   "metadata": {},
   "source": [
    "### 4.5.各类浏览器访问占比分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "319a772f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Chrom      2934\n",
       "FireFox    1821\n",
       "IE         1693\n",
       "Sarfari    1197\n",
       "Other       588\n",
       "Name: 浏览器种类, dtype: int64"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['浏览器种类'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfe69438",
   "metadata": {},
   "source": [
    "通过对浏览器种类进行统计，我们可以发现大多数用户选择使用的是谷歌浏览器，接下来是火狐、IE、sarfari它们三个的\n",
    "使用情况比较平均，最后是使用其他我们并未列出种类的浏览器的用户占一小部分。可以看出，用户对不同浏览器是有所\n",
    "偏爱的，在分析数据中，谷歌浏览器一马当先，证明大多数人是习惯使用谷歌浏览器进行购物的，这其中的原因可能是浏\n",
    "览器对页面解析速度更快或者其他等等原因。而紧随其后的三种浏览器代表了绝大数人的使用情况，选择了一个现有的浏\n",
    "览器，对其并无太多要求。通过以上分析，我觉得厂商可以调整对不同浏览器的广告投放程度，对于用户群体大的chrome\n",
    "可以加大力度，而对于其他小众浏览器可以减少甚至不去投放广告，把资金节约出来可以去优化页面与交互，为用户提供\n",
    "更好的服务，进而吸引更多用户，获得更大的时长份额。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
